package com.qyhl.module_practice.donate.detail;


import com.google.gson.Gson;
import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.basiclib.utils.network.model.ApiResult;
import com.qyhl.webtv.commonlib.common.CommonUtils;

public class PracticeDonateDetailModel implements PracticeDonateDetailContract.PracticeDonateDetailModel {
    private PracticeDonateDetailPresenter mPresenter;

    PracticeDonateDetailModel(PracticeDonateDetailPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void doDonate(String addrId, String name, String address, String phone, String posCode, String content, String remark) {

        EasyHttp.post(PracticeUrl.POST_PRACTICE_DONATE_DETAIL)
                .params("addrId", addrId)
                .params("name", name)
                .params("address", address)
                .params("phone", phone)
                .params("posCode", posCode)
                .params("content", content)
                .params("remark", remark)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.donateError("提交失败，请稍后再试！");
                    }

                    @Override
                    public void onSuccess(String s) {
                        ApiResult apiResult = new Gson().fromJson(s,ApiResult.class);
                        if (apiResult.getCode() == 200) {
                            mPresenter.donateSuccess("提交成功！");
                        } else {
                            mPresenter.donateError("提交出错，请稍后再试！");
                        }
                    }
                });
    }
}
